#include "stm32f10x.h"
void WWDG_Init(uint16_t Window, uint16_t Time)
{
    uint16_t LR = Time * 36000 / 4096 / 8 - 1;
    // enable rcc 
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG, ENABLE);
    // configure wwdg 
    // psc count window-value 
    // 喂狗时间限制 = 1/(36*1000) * 4096 (固定的预分频数) * psc(4位 1 2 4 8) * (LR + 1 )
    // 设定时间限制位50ms ->   50 / (1/32000 * 4096 * 8) = 49
    WWDG_SetPrescaler(WWDG_Prescaler_8);
    // 窗口时间 = 1/(32*1000) * 4096 * psc * (LR - WR)
    WWDG_SetWindowValue(0x40 | (LR - Window * 32000 / 4096 / 8));
    // enable
    WWDG_Enable(0x40 | LR);

}
void WWDG_Reload(uint16_t Time)
{
    uint16_t LR = Time * 36000 / 4096 / 8 - 1;
    WWDG_SetCounter(0x40 | LR);

}